import request from '@/utils/request'
import { type Result } from '@/types/result'
import { type User } from '@/types/user'


// 判断token是否过期
export function checkTokenApi(): Promise<Result> {
  return request.get('/is_login')
}
// 获取验证码
export function getCodeApi(phone: string): Promise<Result> {
  return request.post(`/sendCode?phone=${phone}`)
}
// 密码登录
export function loginWithPasswordApi(phone: string, password: string): Promise<Result> {
  return request.post('/loginWithPassword', { phone, password })
}

// 修改密码
export function changePasswordApi(password: string, confirmPassword: string): Promise<Result> {
  return request.put('/changePassword', null, { params: { password, confirmPassword } })
}

// 验证码登录
export function loginWithCodeApi(phone: string, code: string): Promise<Result> {
  return request.post('/loginWithCode', { phone, code })
}

// 登出
export function logoutApi(): Promise<Result> {
  return request.post('/logout')
}

// 根据用户ID查询用户信息
export function getUserByIdApi(userId: string): Promise<Result> {
  return request.get(`/${userId}`)
}

// 修改用户信息
export function updateUserApi(user: User): Promise<Result> {
  return request.put('',user)
}

// 获取当前登录用户的用户信息
export function getUserInfoApi(): Promise<Result> {
  return request.get('/getUserInfo');
}

